<?php

namespace MyBlog\Http\Controllers\backend;

use Illuminate\Support\Facades\View;
use Illuminate\Support\Facades\Input;
use MyBlog\Models\Gallery;
use MyBlog\Models\Category;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Facades\Redirect;

class GalleryController extends BaseController
{
    public function index() {
        $galleries = Gallery::all();
        
        return view('backend/galleries', compact('galleries'));
    }
    
    public function create() {
    	$gallery = new Gallery();
    	$categoryIds = Category::where('disabled', false)
    			->where('type', Category::TYPE_GALLERIES)
    			->lists('name', 'id');
    	return view('backend/gallery_form', compact('gallery', 'categoryIds'));
    }
    
    public function store() {
    	$input = Input::all();
    	$validation = Validator::make($input, Gallery::$rules, Gallery::$msgs);
    	if($validation->fails()) {
    		return Redirect::back()
	    		->withInput()
	    		->withErrors($validation);
    	}
    	Gallery::create($input);
    	return redirect('backend/galleries');
    }

    public function destory() {

    }
}
